<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>新增用户</title>
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/bootstrap.min.css?v=3.3.5"
	rel="stylesheet">
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/font-awesome.min.css?v=4.4.0"
	rel="stylesheet">
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/animate.min.css"
	rel="stylesheet">
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/style.min.css?v=4.0.0"
	rel="stylesheet">
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/toastr/toastr.min.css"
	rel="stylesheet">

<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/iCheck/custom.css"
	rel="stylesheet">

<link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/chosen/chosen.css" rel="stylesheet"> 
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/bootstrap.min.css?v=3.3.5"
	rel="stylesheet">
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/chosen/chosen.css"
	rel="stylesheet">
<link
	href="<%=request.getContextPath()%>/views/sysdefault/css/style.min.css?v=4.0.0"
	rel="stylesheet">
	    
</head>

<body>
	<div class="ibox-content">

		<form id="subForm"  class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">登录账号</label>
				<div class="col-sm-8">
					<input type="text" name="userAccount" placeholder="请输入用户账号"
						class="form-control" id="tid1" maxlength="60" required="required">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">企业名称</label>
				<div class="col-sm-8">
					<input type="text" name="userName" placeholder="请输入用户企业名称"
						class="form-control" id="tid2" maxlength="20" required="required">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">企业电话</label>
				<div class="col-sm-8">
					<input type="text" name="phone" placeholder="请输入用户企业电话"
						class="form-control" id="tid3" maxlength="20" required="required">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">企业地址</label>
				<div class="col-sm-8">
					<input type="text" name="address" placeholder="请输入用户企业地址"
						class="form-control" id="tid4" maxlength="20" required="required">
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">营业执照</label>
				<div class="col-sm-8">
					<input type="text" name="businessLicense" placeholder="请输入营业执照编号"
					id="tid5"
						class="form-control" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">开户行</label>
				<div class="col-sm-8">
					<input type="text" name="openingBank" placeholder="请输入开户行"
					id="tid6"
						class="form-control" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">开户名称</label>
				<div class="col-sm-8">
					<input type="text" name="openingName" placeholder="请输入开户名称"
					id="tid7"
						class="form-control" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">开户账号</label>
				<div class="col-sm-8">
					<input type="text" name="openingId" placeholder="请输入开户账号"
					id="tid8"
						class="form-control">
				</div>
			</div>
			
			
			
			<div class="form-group">
				<label class="col-sm-2 control-label">用户角色</label>
				<div class="col-sm-10">
					<c:forEach items="${roleList}" var="item" varStatus="i">
						<label class="checkbox-inline i-checks"><input
							type="radio" name="roles" id="roleRadio"
							value="${item.roleId}" style="margin-top:3px" checked>
							${item.roleName}</label>
					</c:forEach>
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="form-group">
				<div class="col-sm-3 col-sm-offset-9">
					<button class="btn btn-primary pull-right m-t-n-xs" type="button" onclick="addRole();">保存内容</button>
				</div>
			</div>

		</form>

	</div>

	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/jquery.min.js?v=2.1.4"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/bootstrap.min.js?v=3.3.5"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/chosen/chosen.jquery.js"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/nouslider/jquery.nouislider.min.js"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/demo/form-advanced-demo.min.js"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/content.min.js?v=1.0.0"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/toastr/toastr.min.js"></script>
	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/layer/layer.js"></script>

	<script
		src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/iCheck/icheck.min.js"></script>


	<script type="text/javascript">
    
    var basePath = '<%=request.getContextPath()%>';
    var existUserName="";
    var hasCharge="";
		toastr.options = {
			"closeButton" : true,
			"debug" : false,
			"progressBar" : true,
			"positionClass" : "toast-top-left",
			"showDuration" : "400",
			"hideDuration" : "1000",
			"timeOut" : "3000",
			"extendedTimeOut" : "1000",
			"showEasing" : "swing",
			"hideEasing" : "linear",
			"showMethod" : "fadeIn",
			"hideMethod" : "fadeOut"
		}

		//初始化页面
		$(function() {
			$(".i-checks").iCheck({
				checkboxClass : "icheckbox_square-green",
				radioClass : "iradio_square-green",
			});
		});

		var addRole = function() {
			debugger;
			/* hasCharge="2";
			var userJobId=$.trim($("#tid5").val());
			if(userJobId!="普通警员(呈报人)"){
				validateCharge();
			}
			if(hasCharge!=false){ */
				validateUserName();
			if(existUserName=="1"){
				var isTrue=validate();
				var index;
				if(isTrue==true){
				$.ajax({
					type : "POST",
					url : basePath + "/system/updateSysUser.do",
					data : $("#subForm").serialize(),
					dataType : "json",
					success : function(msg) {
						if (msg.errCode == '1') {
							parent.layerCallBack('1');
						} else {
							toastr.error(msg.errMsg, "提示");
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						toastr.error("系统出错！", "提示");
					},
					beforeSend : function(XMLHttpRequest) {
						index = layer.load(0, {
							shade : [ 0.3, '#ccc' ]
						//0.1透明度的白色背景
						});
					},
					complete : function(XMLHttpRequest, textStatus) {
						layer.close(index);
					}
				});
				}
			 }
			//}
			/* return false; */
		}
		//检查用户名是否存在
		function validateUserName(){
			debugger;
			var userName=$.trim($("#tid1").val());
			$.ajax({
				type : "POST",
				url : basePath + "/system/validateUserName.do",
				async: false,
				data : "name="+userName,
				dataType : "json",
				success : function(msg) {
					debugger;
					if (msg.errCode == '1') {
						existUserName="1";
					} else {
						toastr.error(msg.errMsg, "提示");
						existUserName=false;
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					toastr.error("系统出错！", "提示");
				}
			});
			
		}
		//检查单位主管或者单位监管是否存在
		function validateCharge(){
			debugger;
			var deparId=$.trim($("#tid4").val());
			var userJobId=$.trim($("#tid5").val());
			var data="deparId="+deparId+"&userJobId="+userJobId;
			$.ajax({
				type : "POST",
				url : basePath + "/system/validateCharge.do",
				async: false,
				data : data,
				dataType : "json",
				success : function(msg) {
					debugger;
					if (msg.errCode == '1') {
						hasCharge="1";
					} else {
						toastr.error(msg.errMsg, "提示");
						hasCharge=false;
						return false;
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					toastr.error("系统出错！", "提示");
				}
			});
			
		}
		//输入限制
		function validate(){
			debugger;
			if($.trim($("#tid1").val())==''){
				toastr.warning("请输入登录账号！", "提示");
				return false;
			}
			else if($.trim($("#tid2").val())==''){
				toastr.warning("请输入真实姓名！", "提示");
				return false;
			}
			else if($.trim($("#tid3").val())==''){
				toastr.warning("请输入企业电话！", "提示");
				return false;
			}
			else if($.trim($("#tid4").val())==''){
				toastr.warning("请输入企业地址！", "提示");
				return false;
			}
			else if($.trim($("#tid5").val())==''){
				toastr.warning("请填写营业执照！", "提示");
				return false;
			}
			else if($.trim($("#tid6").val())==''){
				toastr.warning("请填写开户行！", "提示");
				return false;
			}
			else if($.trim($("#tid7").val())==''){
				toastr.warning("请填写开户名称！", "提示");
				return false;
			}
			else if($.trim($("#tid8").val())==''){
				toastr.warning("请填写开户账号！", "提示");
				return false;
			} 
			else{
				return true;
			}
		}
		//单位选择联动
		function deparChange(){
			debugger;
			var deparId=$.trim($("#tid4").val());
			if(deparId!=""){
				$.ajax({
					type : "POST",
					url : basePath + "/system/getDeparPid.dop",
					data : "&deparId="+deparId,
					dataType : "json",
					success : function(msg) {
						debugger;
						if (msg.errCode == '1') {
							appd(msg.data);
						} 
						else {
							toastr.error(msg.errMsg, "提示");
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						toastr.error("系统出错！", "提示");
					},
					beforeSend : function(XMLHttpRequest) {
						index = layer.load(0, {
							shade : [ 0.3, '#ccc' ]
						//0.1透明度的白色背景
						});
					},
					complete : function(XMLHttpRequest, textStatus) {
						layer.close(index);
					}
				});
				}
			else{
				toastr.error("请选择所在单位！", "提示");
				return false;
			}
				return true
			}
		//单位修改后职位跟着改变
		function appd(data){
        	 debugger;
        	 document.getElementById("tid5").innerHTML = "";
        	 var temp=data
        	 for (var i=0;i<temp.length ;i++ ) 
        	 { 
        		var job=temp[i];
        		//Option(text,value)
        		document.getElementById("tid5").options.add(new Option(job,temp[i]));
        	 } 
         }
	</script>

</body>

</html>